/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package mopso;

/**
 *
 * @author robson
 */
public class DominanceOperators {
    
    public enum Dominance {

        INCOMPARABLE, DOMINATED, DOMINATES
    
    };
    
    public Dominance verifyDominace(Particle particle1, Particle particle2, Problem problem) {

        boolean lostInAllDimension = true;
        boolean winInAllDimension = true;

        for (int j = 0; j < problem.getNObjectives(); j++) {
            if (particle1.getParticleData().getFitness()[j] > particle2.getParticleData().getFitness()[j]) {
                winInAllDimension = false;

                if (!lostInAllDimension) {
                    return Dominance.INCOMPARABLE;
                }
            } //            else if( solution1.getDimensionFitnessValue()[j] == solution2.getDimensionFitnessValue()[j] ) {
            //                return Dominance.CO_DOMINANCE;
            //            }
            else if (particle1.getParticleData().getFitness()[j] < particle2.getParticleData().getFitness()[j]) {
                lostInAllDimension = false;

                if (!winInAllDimension) {
                    return Dominance.INCOMPARABLE;
                }
            }
        }

        if (winInAllDimension && lostInAllDimension) {
            return Dominance.INCOMPARABLE;
        }

        if (winInAllDimension) {
            return Dominance.DOMINATES;
        } else if (lostInAllDimension) {
            return Dominance.DOMINATED;
        } else {
            return Dominance.INCOMPARABLE;
        }
    }  
    
    public Dominance verifyDominace(Particle_CSS particle1, Particle_CSS particle2, Problem problem) {

        boolean lostInAllDimension = true;
        boolean winInAllDimension = true;

        for (int j = 0; j < problem.getNObjectives(); j++) {
            if (particle1.getParticleData().getFitness()[j] > particle2.getParticleData().getFitness()[j]) {
                winInAllDimension = false;

                if (!lostInAllDimension) {
                    return Dominance.INCOMPARABLE;
                }
            } //            else if( solution1.getDimensionFitnessValue()[j] == solution2.getDimensionFitnessValue()[j] ) {
            //                return Dominance.CO_DOMINANCE;
            //            }
            else if (particle1.getParticleData().getFitness()[j] < particle2.getParticleData().getFitness()[j]) {
                lostInAllDimension = false;

                if (!winInAllDimension) {
                    return Dominance.INCOMPARABLE;
                }
            }
        }

        if (winInAllDimension && lostInAllDimension) {
            return Dominance.INCOMPARABLE;
        }

        if (winInAllDimension) {
            return Dominance.DOMINATES;
        } else if (lostInAllDimension) {
            return Dominance.DOMINATED;
        } else {
            return Dominance.INCOMPARABLE;
        }
    } 
    
    public Dominance verifyDominace(ParticleData particleData1, ParticleData particleData2, Problem problem) {

        boolean lostInAllDimension = true;
        boolean winInAllDimension = true;

        for (int j = 0; j < problem.getNObjectives(); j++) {
            if (particleData1.getFitness()[j] > particleData2.getFitness()[j]) {
                winInAllDimension = false;

                if (!lostInAllDimension) {
                    return Dominance.INCOMPARABLE;
                }
            } //            else if( solution1.getDimensionFitnessValue()[j] == solution2.getDimensionFitnessValue()[j] ) {
            //                return Dominance.CO_DOMINANCE;
            //            }
            else if (particleData1.getFitness()[j] < particleData2.getFitness()[j]) {
                lostInAllDimension = false;

                if (!winInAllDimension) {
                    return Dominance.INCOMPARABLE;
                }
            }
        }

        if (winInAllDimension && lostInAllDimension) {
            return Dominance.INCOMPARABLE;
        }

        if (winInAllDimension) {
            return Dominance.DOMINATES;
        } else if (lostInAllDimension) {
            return Dominance.DOMINATED;
        } else {
            return Dominance.INCOMPARABLE;
        }
    }  
    
}
